package com.javastudy.apache.collection;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections4.Predicate;
import org.apache.commons.collections4.functors.EqualPredicate;
import org.apache.commons.collections4.functors.NotNullPredicate;
import org.apache.commons.collections4.functors.UniquePredicate;
import org.apache.commons.collections4.list.PredicatedList;
import org.junit.Test;

//http://blog.csdn.net/scgaliguodong123_/article/details/45874503
public class CollectionTest2 {

	@Test
	public void testPredicate() {
		System.out.println("=====相等判断=======");
        Predicate<String> pre = new EqualPredicate<String>("liguodong");
        //Predicate<String> pre = EqualPredicate.equalPredicate("liguodong");//同上
        boolean flag = pre.evaluate("li");
        System.out.println(flag);
        
        //case-2
        System.out.println("=====非空判断=======");
        Predicate  notNull = NotNullPredicate.INSTANCE;
        //Predicate  notNull = NotNullPredicate.notNullPredicate();//同上
        String str = "lgd";
        System.out.println(notNull.evaluate(str));//非空为true,否则为false。

        //添加容器值得判断
        List<Long> list = PredicatedList.predicatedList(new ArrayList<>(), notNull);
        list.add(1000L);
        //list.add(null);//null值为false， 验证失败，出现异常
        
        
        //case-3
        System.out.println("=====唯一性判断=======");
        Predicate<Long> uniquePre = UniquePredicate.uniquePredicate();      
        List<Long> list1 = PredicatedList.predicatedList(new ArrayList<Long>(),uniquePre);
        list1.add(100L);
        list1.add(200L);
        //list.add(100L);//出现重复值，抛出异常
	}

}
